// TDesign 样式
import 'tdesign-vue-next/es/style/index.css';

import { createPinia } from 'pinia';
import { createApp } from 'vue';

import App from './App.vue';
import router from './router';

// 创建应用实例
const app = createApp(App);

// 配置 Pinia
const pinia = createPinia();
app.use(pinia);

// 配置路由
app.use(router);

// 检查是否在 qiankun 环境中运行
if ((window as any).__POWERED_BY_QIANKUN__) {
  console.log('[MonitorApp] 在 qiankun 环境中运行');

  // 导出生命周期函数供 qiankun 调用
  (window as any).__webpack_public_path__ = (window as any).__INJECTED_PUBLIC_PATH_BY_QIANKUN__;

  // 导出生命周期函数
  (window as any).bootstrap = () => {
    console.log('[MonitorApp] bootstrap');
    return Promise.resolve();
  };

  (window as any).mount = (props: any) => {
    console.log('[MonitorApp] mount', props);
    app.mount('#app');
    return Promise.resolve();
  };

  (window as any).unmount = () => {
    console.log('[MonitorApp] unmount');
    app.unmount();
    return Promise.resolve();
  };
} else {
  console.log('[MonitorApp] 独立运行模式');
  app.mount('#app');
}
